package gang.org.springframework.boot.context.event;

import gang.org.springframework.boot.GangSpringApplication;
import gang.org.springframework.boot.GangSpringApplicationRunListener;
import gang.org.springframework.framework.context.GangApplicationListener;
import gang.org.springframework.framework.context.GangConfigurableApplicationContext;

import java.util.Set;


public class GangEventPublishingRunListener implements GangSpringApplicationRunListener {

    private final GangSpringApplication application;
    private final String[] args;

    public GangEventPublishingRunListener(GangSpringApplication application, String[] args) {
        this.application = application;
        this.args = args;
    }

    /**
     * TODO
     * 业务意义
     * 1） 将Springboot资源工厂ApplicationListener接口类所有接口实现工厂类监听器初始化到集合
     * */
    @Override
    public void contextLoaded(GangConfigurableApplicationContext context) {

        Set<GangApplicationListener> listeners = application.getListeners();

        for (GangApplicationListener listener : listeners) {

            context.addApplicationListener(listener);
        }
    }
}
